var gulp = require('gulp'),
    sass = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    connect = require('gulp-connect'),
    imagemin = require('gulp-imagemin'),
    notify = require('gulp-notify');

var autoprefixer_config = {
  browsers: [
    "ie >=9",
    "chrome >= 37",
    "ios >= 7",
    "android >= 2.3",
  ]
}

gulp.task('image',function(){
  gulp.src('images/**')
    .pipe(imagemin())
    .pipe(gulp.dest('images'))
})

gulp.task('server',function(){
  connect.server({
    root: '',
    livereload: true
  });
})

gulp.task('scss-monitor',function(){
  return gulp.src('src/application.scss')
    .pipe(sass({outputStyle: 'expanded'})
      .on('error', sass.logError))
    .pipe(autoprefixer(autoprefixer_config))
    .pipe(gulp.dest('example'))
    .pipe(connect.reload());
})

gulp.task('watch',function(){
  var t = gulp.watch('src/**',['scss-monitor']);
  gulp.watch('example/*.html',function(e){
    gulp.src(e.path)
      .pipe(connect.reload());
  })
  // t.on('change',function(event){
  //   console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  // })
})

gulp.task('notify',function(){
  gulp.src('src/application.scss')
    .pipe(notify('secret，午时已到'));
})

gulp.task('default',['server','watch'])